package com.senmiao.ssm.utils;

import com.senmiao.ssm.constants.MyConstants;
import org.apache.shiro.crypto.hash.Sha1Hash;

import java.util.UUID;

public class EncryptUtils {

    /**
     * 生成长度为32的密码盐
     * @return
     */
    public static String generateSalt(){
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    public static String encryptPassword(String password,String salt){
        Sha1Hash sha1Hash = new Sha1Hash(password,salt,MyConstants.INTERATIONS);
//        sha1Hash.setIterations(MyConstants.INTERATIONS);
        return sha1Hash.toHex();
    }

    public static String simpleHash(String password,String salt){
        return new Sha1Hash(password, salt, MyConstants.INTERATIONS).toHex();
    }

    public static void main(String[] args) {
        String salt = generateSalt();
//        String salt = "abcd";
        System.out.println(salt);
        System.out.println(salt.length());
        System.out.println(encryptPassword("123", salt));
        String x = simpleHash("123", salt);
        System.out.println(x.length());
    }

}